//
//  AddViewController.m
//  CoreDataAddressBook
//
//  Created by WangZe on 15/11/21.
//  Copyright © 2015年 王泽龙. All rights reserved.
//

#import "AddViewController.h"
#import "WZLCoreData.h"
#import "Contact.h"
@interface AddViewController ()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UILabel *sexLabel;
@property (weak, nonatomic) IBOutlet UITextField *sexTextField;

@property (weak, nonatomic) IBOutlet UITextField *numTextField;
@property (weak, nonatomic) IBOutlet UILabel *numLabel;
@property (weak, nonatomic) IBOutlet UILabel *tempLabel;
@property (weak, nonatomic) IBOutlet UITextField *tempTextField;

@property (weak, nonatomic) IBOutlet UILabel *QQLabel;
@property (weak, nonatomic) IBOutlet UITextField *QQTextField;
@property (nonatomic, strong) WZLCoreData *manager;
- (IBAction)saveButton:(UIButton *)sender;
- (IBAction)returnButton:(UIButton *)sender;

@end

@implementation AddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.manager = [WZLCoreData shareWZLCoreDataManager];
}

- (IBAction)saveButton:(UIButton *)sender {
    // 创建实体描述
    // 参数1 : 描述的实体
    // 参数2 : 数据管理器
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Contact" inManagedObjectContext:self.manager.managedObjectContext];
    // 创建实体
    // 参数1 : 实体描述文件
    // 参数2 : 数据管理器
    Contact *stu = [[Contact alloc] initWithEntity:entity insertIntoManagedObjectContext:self.manager.managedObjectContext];
    
    stu.name = self.nameTextField.text;
    stu.sex = self.sexTextField.text;
    stu.tem = [NSNumber numberWithFloat:[self.tempTextField.text floatValue]];
    stu.number = [NSNumber numberWithFloat:[self.numTextField.text floatValue]];
    stu.qq = [NSNumber numberWithFloat:[self.QQTextField.text floatValue]];
    [self.manager saveContext];
    
}

- (IBAction)returnButton:(UIButton *)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
